void main() {
  final myDataSource = MyDataSource<int>();
  myDataSource.addData(1);
  myDataSource.addData(2);
  myDataSource.addData(3);
  print(myDataSource.getListCount());
  print(myDataSource.getData(1));
}

/// 数据源接口 (只负责定义, 不实现)
abstract interface class IDataSource<T> {
  int getListCount();
  T getData(int index);
}

class MyDataSource<T> implements IDataSource<T> {
  // 数据列表
  List<T> _dataList = [];

  @override
  int getListCount() {
    return _dataList.length;
  }

  @override
  T getData(int index) {
    return _dataList[index];
  }

  void addData(T data) {
    _dataList.add(data);
  }
}
